
/**
 * 3-Component Vector class
 * @author gordon
 */
public class Vector3 implements IVector3 {

    protected int x, y, z;

    public Vector3() {
        x = 0;
        y = 0;
        z = 0;
    }

    public int x() {
        return x;
    }

    public int y() {
        return y;
    }

    public int z() {
        return z;
    }

    public void set(int x, int y, int z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    public void set(IVector3 rhs) {
        x = rhs.x();
        y = rhs.y();
        z = rhs.z();
    }

    public void add(IVector3 rhs) {
        x += rhs.x();
        y += rhs.y();
        z += rhs.z();
    }

    public void subtract(IVector3 rhs) {
        x -= rhs.x();
        y -= rhs.y();
        z -= rhs.z();
    }

    public void scale(int scale) {
        x = FP.mul(x, scale);
        y = FP.mul(y, scale);
        z = FP.mul(z, scale);
    }

    public void invScale(int scale) {
        x = FP.div(x, scale);
        y = FP.div(y, scale);
        z = FP.div(z, scale);
    }

    public int length() {        
        return FP.sqrt(
                (long)x*(long)x
                + (long)y*(long)y
                + (long)z*(long)z);
    }

    public void unit() {
        invScale(length());
    }

}
